package com.method;

/**
 * @Author WaveHi
 * @Date 29/7/2021 上午 11:09
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description 求受折扣影响的的商品总价格
 */
public class MethodDemo4 {

    public static void main(String[] args) {

        //获取商品折扣
        double cutRate = 0.5;

        //获取商品价格
        int[] shops = {133,2312,312,4213,54,34,56,464,5634,31};

        System.out.println("商品总价格为" + MethodDemo4.getCutPrice(shops,cutRate));

        System.out.println(MethodDemo4.getCutPriceUp(0.2,12,12,312,3));

    }

    /**
     * 求商品的折扣价格
     * @param shops 商品
     * @param cutRate 折扣
     * @return 折扣后的总价格
     */
    public static double getCutPrice(int[] shops,double cutRate) {

        //定义变量接收商品的总价格
        int sum = 0;

        //使用for循环结构来求商品的总价格
        for(int index = 0;index < shops.length;index++){
            sum += shops[index];
        }

        //计算打折扣后的商品总价格
        return sum * cutRate;

    }

    public static double getCutPriceUp(double cutRate,int... shops) {

        //定义变量接收商品总价格
        int sum = 0;

        //使用for循环结构求商品总价格
        for(int index = 0;index < shops.length;index++){
            sum += shops[index];
        }

        //计算
        return sum * cutRate;

    }

}
